package edu.szu.huhanpeng.doodlingFight.controller.dataController.turnPlayer 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.model.ChessGroupProxy;
	import edu.szu.huhanpeng.doodlingFight.model.GameProxy;
	import edu.szu.huhanpeng.doodlingFight.model.ScoreProxy;
	import edu.szu.huhanpeng.doodlingFight.view.GameWindowMed;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class RobotDc extends SimpleCommand implements ICommand, INotifier 
	{
		
		override public function execute(note:INotification):void 
		{
			var isOnePlayer:Boolean = (facade.retrieveProxy(GameProxy.NAME) as GameProxy).isOnePlayer();
			if ( !isOnePlayer || isPlayerOneActing() )
			{
				return;
			}
			
			var gameWindowMed:GameWindowMed = facade.retrieveMediator( GameWindowMed.NAME ) as GameWindowMed;
			gameWindowMed.disableInteract();
			
			var groupProxy:ChessGroupProxy = facade.retrieveProxy( ChessGroupProxy.NAME ) as ChessGroupProxy;
			sendNotification( GlobalConst.noteName.EXCHANGE, groupProxy.getRobotMove() );
		}
		
		private function isPlayerOneActing():Boolean 
		{
			var gameProxy:GameProxy = facade.retrieveProxy( GameProxy.NAME ) as GameProxy;
			if ( facade.retrieveProxy(ScoreProxy.NAME).getData() == gameProxy.pOneScoreData ) 
			{
				return true;
			}
			else
			{
				return false;
			}
			
		}
		
	}

}